#!/bin/bash

#  ADB Uninstall.sh
#  
#  This script works on Linux and Mac OS X.
#  This script removed adb and fastboot from usr/bin/
#
#  Created by kalaker on 4/21/12.
#
#  	Updated by Marco von Hagen on 01.04.15 18:25
#	changed to /usr/local/bin
#	check if exists at /usr/local/bin
#	check if not Darwin when removing rules

REMOVE_PATH="/usr/local/bin"
echo "About to remove ADB and Fastboot"
echo "from $REMOVE_PATH."
echo "We're accessing protected directories, please type your password."
sudo cd $(pwd)

echo "Removing ADB..."
if [ $(test -e $REMOVE_PATH/adb) ]  		# if exists
then
	sudo rm "$REMOVE_PATH/adb" 			# Removes adb
	[ "$?" ] && 
	echo "ADB removed" || 				# claim success
	echo "ADB not removed" 				# something went wrong
else
echo "ADB not found in $REMOVE_PATH."	# no ADB here
fi

echo "Removing Fastboot..."
if [ $(test -e $REMOVE_PATH/fastboot) ] 	# if exists
then	
	sudo rm "$REMOVE_PATH/fastboot" 	# Remove fastboot
	[ "$?" ] && 
	echo "Fastboot removed" || 			# claim success
	echo "Fastboot not removed";		# ups...
else
echo "Fastboot not in $REMOVE_PATH."	# no Fastboot here
fi

# ####
# if [ "`uname -s`" == "Darwin" ] 		# check to be Darwin 
# then		
# 	echo "check IF THEN "
# 	[ "`ls /usr/local/bin`" ] &&
# 	echo "bin found" #Removes rules
# #	echo "If you're on a Mac and that last line was an error, it's okay."
# #	not needed anymore
# 	echo "Rules removed"
# fi
# 
# ####



if [ "$(uname -s)" != "Darwin" ] 		# check not to be Darwin 
then		
	echo "Removing rules"
	[ $(test -e /etc/udev/rules.d/51-android.rules) ] &&	# if file exists
	sudo rm /etc/udev/rules.d/51-android.rules #Removes rules
#	echo "If you're on a Mac and that last line was an error, it's okay."
#	not needed anymore
	echo "Rules removed"
fi

#	we claimed success on every single step, just say bye.
#echo "ADB and Fastboot have been successfully removed."
echo "Have a nice day!"

